// 老子要开始乱来了,再改再改
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {


    issuccessMask: false,
    tonzhi: false,
    typeIndex: 0,
    workList: [],
    issuccessMaskes: false,

    workobj1: {
      bricklayTotalSize: "",
      bricklayGlueDosage: "",
      superviseCheckProof: "",
      superviseCheckProof: [],
      bricklayPlaceProof: [],
      bricklayPanoramaProof: [],
      bricklaySpecificProof: [],
      zong: 0
    },

    workobj2: {
      bricklayTotalSize: "",
      bricklayGlueDosage: "",
      superviseCheckProof: "",
      superviseCheckProof: [],
      bricklayPlaceProof: [],
      bricklayPanoramaProof: [],
      bricklaySpecificProof: [],
      zong: 0
    },
    workobj3: {
      bricklayTotalSize: "",
      bricklayGlueDosage: "",
      superviseCheckProof: "",
      superviseCheckProof: [],
      bricklayPlaceProof: [],
      bricklayPanoramaProof: [],
      bricklaySpecificProof: [],
      zong: 0
    }


  },
  bindtonzhi() {
    this.saveSuperviseNotice()
  },



  HidedispatcCarer() {
    this.setData({
      tonzhi: false,
      issuccessMaskes: false,
    })
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2]; //prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。\\
    prevPage.getOrderDetails()
    // prevPage.setData({
    //   todo: ''
    // })
    wx.navigateBack({
      delta: 1,
    })

  },
  // 上传附件
  upload(arr) {
    return new Promise((reslove, reject) => {
      if (arr.length == 0) {
        reslove([])
        return
      }
      wx.showLoading({
        title: '上传中...', //提示的内容
        mask: true //显示透明蒙层 防止触摸穿透
      })
      let finishFilesList = []
      arr.forEach((item, index) => {
        wx.uploadFile({
          url: app.globalData.Interfaceurl + 'saveFileUpload',
          filePath: item,
          name: 'file',
          formData: {
            userId: app.globalData.userId,

          },
          header: {
            "content-type": "multipart/form-data"
          },
          success: function (res) {
            finishFilesList.push(JSON.parse(res.data).fileUrl)
            if (index >= arr.length - 1) {

              setTimeout(() => {
                wx.hideLoading();
                reslove(finishFilesList)
              }, 500)
            }
          },
          fail: err => {
            return err
          }
        })
      })
    })
  },
  showmask() {






    if (wx.getStorageSync('up') == false) {
      wx.setStorageSync('up', true)
      this.yanshiqi = setTimeout(() => {
        wx.setStorageSync('up', false)
      }, 1000);
      let workList = []
      this.data.workList.forEach(item => {
        let obj = {
          workId: item.id,
          token: app.token(),
          bricklayPaySize: item.bricklayPaySize,
          bricklayPayAmount: item.bricklayPayAmount,
          bricklaySlurryThickness: item.bricklaySlurryThickness,
          bricklaySlurryThicknessProof: item.bricklaySlurryThicknessProof == "" ? [] : item.bricklaySlurryThicknessProof,
          bricklayActualEndDate: item.bricklayActualEndDate,
          bricklayActualDuration: item.bricklayActualDuration,
          workType: item.workType,
          bricklayUnitName: item.bricklayUnitName,
          inCheckDate: item.inCheckDate
        }
        if (this.data.typeIndex == 0) {
          obj.bricklayGlueDosage = this.data.workobj1.bricklayGlueDosage
          obj.bricklayPanoramaProof = this.data.workobj1.bricklayPanoramaProof
          obj.bricklayPlaceProof = this.data.workobj1.bricklayPlaceProof
          obj.bricklaySpecificProof = this.data.workobj1.bricklaySpecificProof
          obj.superviseCheckProof = this.data.workobj1.superviseCheckProof
          obj.bricklayTotalSize = this.data.workobj1.bricklayTotalSize


        } else if (this.data.typeIndex == 1) {


          obj.bricklayGlueDosage = this.data.workobj2.bricklayGlueDosage
          obj.bricklayPanoramaProof = this.data.workobj2.bricklayPanoramaProof
          obj.bricklayPlaceProof = this.data.workobj2.bricklayPlaceProof
          obj.bricklaySpecificProof = this.data.workobj2.bricklaySpecificProof
          obj.superviseCheckProof = this.data.workobj2.superviseCheckProof
          obj.bricklayTotalSize = this.data.workobj2.bricklayTotalSize


        } else if (this.data.typeIndex == 2) {


          obj.bricklayGlueDosage = this.data.workobj3.bricklayGlueDosage
          obj.bricklayPanoramaProof = this.data.workobj3.bricklayPanoramaProof
          obj.bricklayPlaceProof = this.data.workobj3.bricklayPlaceProof
          obj.bricklaySpecificProof = this.data.workobj3.bricklaySpecificProof
          obj.superviseCheckProof = this.data.workobj3.superviseCheckProof
          obj.bricklayTotalSize = this.data.workobj3.bricklayTotalSize


        }
        workList.push(obj)
      })

      let arr
      if (this.data.typeIndex == 0) {
        arr = workList.filter(item => item.workType == 1)
        if (arr.some(item => item.superviseCheckProof.length == 0)) {
          wx.showToast({
            title: '请上传验收表',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayUnitName == "天" && item.bricklayActualEndDate == '')) {
          wx.showToast({
            title: '请输入实际完工时间',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayUnitName == "m²" && item.bricklayPaySize == '')) {
          wx.showToast({
            title: '请填写实际铺贴面积',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayGlueDosage == '')) {
          wx.showToast({
            title: '请填写瓷砖胶用量',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklaySlurryThickness == '')) {
          wx.showToast({
            title: '请填写浆层厚度',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklaySlurryThicknessProof.length == 0)) {
          wx.showToast({
            title: '请上传浆层厚度图',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayPlaceProof.length == 0)) {
          wx.showToast({
            title: '请上传各位置图',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayPanoramaProof.length == 0)) {
          wx.showToast({
            title: '请上传整体效果图',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklaySpecificProof.length == 0)) {
          wx.showToast({
            title: '请上传细节图',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }

      } else if (this.data.typeIndex == 1) {

        arr = workList.filter(item => item.workType == 2)
        if (arr.some(item => item.superviseCheckProof.length == 0)) {
          wx.showToast({
            title: '请上传验收表',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }

        if (arr.some(item => item.bricklaySpecificProof.length < 3)) {
          wx.showToast({
            title: '上传细节图不能小于3张',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayPanoramaProof.length == 0)) {
          wx.showToast({
            title: '请上传全景图',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }



      } else {
        arr = workList.filter(item => item.workType == 3)
        if (arr.some(item => item.bricklaySpecificProof.length < 3)) {

          wx.showToast({
            title: '上传细节图不能小于3张',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.superviseCheckProof.length == 0)) {
          wx.showToast({
            title: '请上传验收表',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
        if (arr.some(item => item.bricklayPanoramaProof.length == 0)) {
          wx.showToast({
            title: '请上传全景图',
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          return
        }
      }

      arr.forEach(async (item, index) => {

        item.superviseCheckProof = await this.upload(item.superviseCheckProof)
        if (item.inCheckDate == '') {
          item.bricklaySlurryThicknessProof = await this.upload(item.bricklaySlurryThicknessProof)
        } else {
          item.bricklaySlurryThicknessProof = item.bricklaySlurryThicknessProof.map(item => item.replace(app.globalData.Imageurl, ''))
        }
        item.bricklayPlaceProof = await this.upload(item.bricklayPlaceProof)
        item.bricklayPanoramaProof = await this.upload(item.bricklayPanoramaProof)
        item.bricklaySpecificProof = await this.upload(item.bricklaySpecificProof)


        await this.saveSuperviseCheck(item)
        if (index == arr.length - 1) {
          wx.hideLoading();
          this.getOrderDetails(true)
        }
      })
    }
  },
  // 项目详情接口
  getOrderDetails(showmak) {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderDetails',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        // userId: 1569562832576524288,
        orderId: t.data.orderId,
      },
      success: res => {
        wx.hideLoading();
        let workList = res.data.workList.filter(item=>item.bricklayId!='')
        workList.forEach(item => {
          if (item.bricklayActualDuration == '') {
            item.bricklayActualDuration = t.timediff(item.bricklayBeginDate, t.data.nowday)
          }

          if (item.bricklayActualEndDate == '') {
            item.bricklayActualEndDate = ''
          }

          if (item.bricklaySlurryThicknessProof != '') {
            item.bricklaySlurryThicknessProof = (item.bricklaySlurryThicknessProof.split(",")).map(item1 => t.data.Imageurl + item1)
          } else {
            item.bricklaySlurryThicknessProof = []
          }
          if (item.bricklayPayAmount == '') {
            if (item.bricklayUnitName == "天") {
              item.bricklayPayAmount = item.bricklayActualDuration * item.bricklayUnitPrice
            } else if ("m²") {
              //  bricklayPaySize
              item.bricklayPayAmount = item.bricklayPaySize * item.bricklayUnitPrice
            }
          }
        })




        t.setData({
          workList: workList,
          workList1: workList.filter(item => item.workType == 1),
          workList2: workList.filter(item => item.workType == 2),
          workList3: workList.filter(item => item.workType == 3),

        })
        let one = workList.filter(item => item.workType == 1)
        let workobj1 = this.data.workobj1

        if (one.length != 0) {
          workobj1.zong = one.reduce((total, currentValue) => total + Number(currentValue.bricklayPayAmount), 0)
          t.setData({
            workobj1: workobj1,
          })
          if(!one.some(item=>item.inCheckDate=='')){
            if(one[0].bricklayGlueDosage){
              workobj1.bricklayGlueDosage = one[0].bricklayGlueDosage
            }
            if(one[0].bricklayTotalSize){
              workobj1.bricklayTotalSize = one[0].bricklayTotalSize
            }
            if (one[0].superviseCheckProof != "") {
              workobj1.superviseCheckProof = one[0].superviseCheckProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 

            if (one[0].bricklayPlaceProof != "") {
              workobj1.bricklayPlaceProof = one[0].bricklayPlaceProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (one[0].bricklayPanoramaProof != "") {
              workobj1.bricklayPanoramaProof = one[0].bricklayPanoramaProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (one[0].bricklaySpecificProof != "") {
              workobj1.bricklaySpecificProof = one[0].bricklaySpecificProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            t.setData({
              workobj1: workobj1,
            })
          }
        }

        let two = workList.filter(item => item.workType == 2)
        if (two.length != 0) {
          let workobj2 = this.data.workobj2
          workobj2.zong = two.reduce((total, currentValue) => total + Number(currentValue.bricklayPayAmount), 0)
          t.setData({
            workobj2: workobj2,
          })
          if(!two.some(item=>item.inCheckDate=='')){
            if(two[0].bricklayGlueDosage){
              workobj2.bricklayGlueDosage = two[0].bricklayGlueDosage
            }
            if(two[0].bricklayTotalSize){
              workobj2.bricklayTotalSize = two[0].bricklayTotalSize
            }
            if (two[0].superviseCheckProof != "") {
              workobj2.superviseCheckProof = two[0].superviseCheckProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 

            if (two[0].bricklayPlaceProof != "") {
              workobj2.bricklayPlaceProof = two[0].bricklayPlaceProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (two[0].bricklayPanoramaProof != "") {
              workobj2.bricklayPanoramaProof = two[0].bricklayPanoramaProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (two[0].bricklaySpecificProof != "") {
              workobj2.bricklaySpecificProof = two[0].bricklaySpecificProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            t.setData({
              workobj2: workobj2,
            })
          }
        }
        let treen = workList.filter(item => item.workType == 3)
        if (treen.length != 0) {
          let workobj3 = this.data.workobj3
          workobj3.zong = treen.reduce((total, currentValue) => total + Number(currentValue.bricklayPayAmount), 0)
          t.setData({
            workobj3: workobj3
          })
          if(!treen.some(item=>item.inCheckDate=='')){
            if(treen[0].bricklayGlueDosage){
              workobj3.bricklayGlueDosage = treen[0].bricklayGlueDosage
            }
            if(treen[0].bricklayTotalSize){
              workobj3.bricklayTotalSize = treen[0].bricklayTotalSize
            }
            if (treen[0].superviseCheckProof != "") {
              workobj3.superviseCheckProof = treen[0].superviseCheckProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (treen[0].bricklayPlaceProof != "") {
              workobj3.bricklayPlaceProof = treen[0].bricklayPlaceProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (treen[0].bricklayPanoramaProof != "") {
              workobj3.bricklayPanoramaProof = treen[0].bricklayPanoramaProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            if (two[0].bricklaySpecificProof != "") {
              workobj3.bricklaySpecificProof = treen[0].bricklaySpecificProof.split(",").map(item1 => this.data.Imageurl + item1)
            } 
            t.setData({
              workobj3: workobj3,
            })
          }
        }


        if (showmak == true) {


          if (workList.some(item => item.inCheckDate == '')) {
            this.setData({
              issuccessMask: true
            })

          } else {
            this.setData({
              tonzhi: true,
              token: app.token(),

            })


          }

          wx.setStorageSync('up', false)
        }






      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },
  HidedispatcCar() {


    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2]; //prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。\\





    this.setData({
      issuccessMask: false,

      todo: 'previewacceptance'
    })
    wx.setStorageSync('istab', true)
    this.getOrderDetails()
    clearTimeout(this.yanshiqi)
  },
  goorderdectio() {
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2]; //prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。\\
    prevPage.setData({
      todo: ''
    })
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?orderId=' + this.data.orderId,
    })
  },







  Unplonecontract(e) {
    let index = e.currentTarget.dataset.index
    let todo = e.currentTarget.dataset.todo
    let workList = this.data.workList
    workList[index][todo] = e.detail
    this.setData({
      workList: workList
    })

  },

  Unplonethickness(e) {

    let index = e.currentTarget.dataset.index
    let todo = e.currentTarget.dataset.todo
    let workList = this.data.workList
    workList[index][todo] = e.detail
    this.setData({
      workList: workList
    })
  },
  saveSuperviseNotice() {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'saveSuperviseNotice',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        orderId: t.data.orderId,
        token: t.data.token,

      },
      success: res => {
        wx.hideLoading()
        if (res.data.result == 0) {

          t.setData({
            issuccessMaskes: true
          })



        } else {
          wx.showToast({
            title: res.data.message,
            duration: 2500, //持续的时间
            icon: 'none', //图标
          })
          t.setData({
            token: t.token()
          })
        }




      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },



  saveSuperviseCheck(obj) {
    let t = this
    console.log(obj)

    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    return new Promise((reslove, reject) => {
      if (t.data.zhuabpai) {
        wx.request({
          url: app.globalData.Interfaceurl + 'saveSuperviseCheck',
          method: "post",
          header: {
            "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
          },
          data: {
            userId: app.globalData.userId,
            workId: obj.workId,
            token: obj.token,
            orderId: t.data.orderId,
            superviseCheckProof: obj.superviseCheckProof.join(","),
            bricklayPaySize: obj.bricklayPaySize,
            bricklayPayAmount: obj.bricklayPayAmount,
            bricklayGlueDosage: obj.bricklayGlueDosage,
            bricklaySlurryThickness: obj.bricklaySlurryThickness,
            bricklaySlurryThicknessProof: obj.bricklaySlurryThicknessProof.join(","),
            bricklayActualEndDate: obj.bricklayActualEndDate,
            bricklayActualDuration: obj.bricklayActualDuration,
            bricklayPlaceProof: obj.bricklayPlaceProof.join(),
            bricklayPanoramaProof: obj.bricklayPanoramaProof.join(),
            bricklaySpecificProof: obj.bricklaySpecificProof.join(),
            bricklayTotalSize: obj.bricklayTotalSize
          },
          success: res => {

            if (res.data.result == 0) {
              reslove(res.data.result)
            } else {
              wx.showToast({
                title: res.data.message,
                duration: 2500, //持续的时间
                icon: 'none', //图标
              })
              t.setData({
                token: t.token()
              })
            }




          },
          fail: err => {
            wx.showToast({
              title: '请求失败',
              duration: 2500, //持续的时间
              icon: 'none', //图标
            })
          }
        })
      } else {
        wx.request({
          url: app.globalData.Interfaceurl + 'saveSuperviseCheck',
          method: "post",
          header: {
            "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
          },
          data: {
            userId: app.globalData.userId,
            workId: obj.workId,
            token: obj.token,
            orderId: t.data.orderId,
            superviseCheckProof: obj.superviseCheckProof.join(","),
            bricklayPaySize: obj.bricklayPaySize,
            bricklayPayAmount: obj.bricklayPayAmount,
            bricklayGlueDosage: obj.bricklayGlueDosage,
            bricklaySlurryThickness: obj.bricklaySlurryThickness,
            bricklaySlurryThicknessProof: obj.bricklaySlurryThicknessProof.join(","),
            bricklayActualEndDate: obj.bricklayActualEndDate,
            bricklayActualDuration: obj.bricklayActualDuration,
            bricklayPlaceProof: obj.bricklayPlaceProof.join(),
            bricklayPanoramaProof: obj.bricklayPanoramaProof.join(),
            bricklaySpecificProof: obj.bricklaySpecificProof.join(),
            bricklayTotalSize: obj.bricklayTotalSize
          },
          success: res => {

            if (res.data.result == 0) {
              reslove(res.data.result)
            } else {
              wx.showToast({
                title: res.data.message,
                duration: 2500, //持续的时间
                icon: 'none', //图标
              })
              t.setData({
                token: t.token()
              })
            }




          },
          fail: err => {
            wx.showToast({
              title: '请求失败',
              duration: 2500, //持续的时间
              icon: 'none', //图标
            })
          }
        })
      }
    })
  },

  bindtype(e) {
    let typeIndex = e.currentTarget.dataset.type
    this.setData({
      typeIndex: typeIndex
    })
  },


  //计算两个时间差  返回天小时分钟
  timediff(begin_time, end_time) {
    //年月日时分秒转换为时间戳
    let beginTime = (new Date(begin_time).getTime()) / 1000;
    let endTime = (new Date(end_time).getTime()) / 1000;
    var starttime = ''
    var endtime = ''
    if (beginTime < endTime) {
      starttime = beginTime;
      endtime = endTime;
    } else {
      starttime = endTime;
      endtime = beginTime;
    }
    //计算天数
    var timediff = endtime - starttime;
    var days = Math.floor(timediff / 86400) + 1;
    // //计算小时数
    // var remain = timediff % 86400;
    // var hours = parseInt(remain / 3600);
    //计算分钟数
    // var remain = remain % 3600;
    // var mins = parseInt(remain / 60);
    // var res = days + '天' + hours + '小时' + mins + '分';
    return days;
  },
  bindDateChange(e) {
    let index = e.currentTarget.dataset.index
    let workList = this.data.workList
    workList[index].bricklayActualEndDate = e.detail.value
    workList[index].bricklayActualDuration = this.timediff(workList[index].bricklayBeginDate, workList[index].bricklayActualEndDate)
    if (workList[index].bricklayUnitName == "天") {
      // 
      workList[index].bricklayPayAmount = workList[index].bricklayActualDuration * workList[index].bricklayUnitPrice
    } else {
      workList[index].bricklayPayAmount = workList[index].bricklayBudgetSize * workList[index].bricklayUnitPrice
    }
    if (this.data.typeIndex == 0) {
      let one = workList.filter(item => item.workType == 1)
      let workobj1 = this.data.workobj1
      workobj1.zong = one.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)

      this.setData({
        workobj1: workobj1
      })
    } else if (this.data.typeIndex == 1) {
      let two = workList.filter(item => item.workType == 2)
      let workobj2 = this.data.workobj2
      workobj2.zong = two.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)
      this.setData({
        workobj2: workobj2
      })
    } else if (this.data.typeIndex == 2) {
      let treen = workList.filter(item => item.workType == 3)
      let workobj3 = this.data.workobj3
      workobj3.zong = treen.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)

      this.setData({
        workobj3: workobj3
      })
    }


    this.setData({
      workList: workList
    })
  },
  jianchen(e) {
    let index = e.currentTarget.dataset.index
    let todo = e.currentTarget.dataset.todo
    let workList = this.data.workList

    workList[index][todo] = e.detail.value
    if (todo == "bricklayPaySize") {
      workList[index].bricklayPayAmount = workList[index].bricklayPaySize * workList[index].bricklayUnitPrice

      if (this.data.typeIndex == 0) {
        let one = workList.filter(item => item.workType == 1)
        let workobj1 = this.data.workobj1
        workobj1.zong = one.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)

        this.setData({
          workobj1: workobj1
        })
      } else if (this.data.typeIndex == 1) {
        let two = workList.filter(item => item.workType == 2)
        let workobj2 = this.data.workobj2
        workobj2.zong = two.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)
        this.setData({
          workobj2: workobj2
        })
      } else if (this.data.typeIndex == 2) {
        let treen = workList.filter(item => item.workType == 3)
        let workobj3 = this.data.workobj3
        workobj3.zong = treen.reduce((total, currentValue) => total + (currentValue.bricklayPayAmount - 0), 0)

        this.setData({
          workobj3: workobj3
        })
      }


    }




    this.setData({
      workList: workList
    })
  },


  yanshou(e) {
    let typeIndex = this.data.typeIndex
    let todo = e.currentTarget.dataset.todo
    let value = e.detail.value
    if (typeIndex == 0) {
      let workobj1 = this.data.workobj1
      workobj1[todo] = value
      this.setData({
        workobj1: workobj1
      })
    }
    if (typeIndex == 1) {

      let workobj2 = this.data.workobj2
      workobj2[todo] = value
      this.setData({
        workobj2: workobj2
      })
    }
    if (typeIndex == 2) {
      let workobj3 = this.data.workobj3
      workobj3[todo] = value
      this.setData({
        workobj3: workobj3
      })
    }

  },

  uploneyanshou(e) {
    let typeIndex = this.data.typeIndex
    let todo = e.currentTarget.dataset.todo
    let value = e.detail
    console.log(e)
    if (typeIndex == 0) {
      let workobj1 = this.data.workobj1
      workobj1[todo] = value
      this.setData({
        workobj1: workobj1
      })

      console.log(workobj1)
    }
    if (typeIndex == 1) {
      let workobj2 = this.data.workobj2
      workobj2[todo] = value
      this.setData({
        workobj2: workobj2
      })
    }
    if (typeIndex == 2) {
      let workobj3 = this.data.workobj3
      workobj3[todo] = value
      this.setData({
        workobj3: workobj3
      })
    }
  },
  fakeCallback() {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let date = new Date()
    let year = date.getFullYear()
    let mouth = date.getMonth() + 1
    mouth = mouth >= 10 ? mouth : "0" + mouth
    let d = date.getDate()
    d = d >= 10 ? d : "0" + d
    let nowday = year + "-" + mouth + "-" + d









    this.setData({
      orderId: options.orderId,
      nowday: nowday,
      token: app.token(),
      Imageurl: app.globalData.Imageurl,
      // workList: workList,
    })


    this.getOrderDetails()
    if (options.todo) {
      this.setData({
        todo: options.todo
      })
    }
    if (options.todo == 'previewacceptance') {
      this.getOrderDetails()
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.setStorageSync('up', false)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    wx.removeStorageSync("up")
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    wx.removeStorageSync("up")
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})